<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>发送jsonp请求</button>
    <div></div>
    <script>
        // 4. 定义一个函数
        function fn(data){
            console.log('客户端获取的data数据: ', data);
            let oDiv = document.querySelector('div');
            oDiv.innerHTML = data;
        }
        oBtn = document.querySelector('button');

        oBtn.onclick = function(){
            // 1. 创建一个script标签
            const oScript = document.createElement('script');
            // 2. 给script标签添加src，值是要请求的后端路由
            oScript.src = 'http://localhost:8080/jsonp?cb=fn';
            // 3. 将script 标签添加到页面
            document.body.appendChild(oScript);
        }
    </script>
    <!-- <script src="http://localhost:8080/jsonp"></script> -->
</body>
</html>